import { http } from "@/utils/http";
import { PageParams, CommonResponse } from "./common";

export type AccountResult = {
  records: {
    id: number;
    name: string;
    account: string;
    roleName: string;
    roleId: string;
    gmtCreate: Date;
    createBy: string;
    status: string | null;
  }[]
  total: number;
  pageNum: number;
  pageSize: number
};

/**
 * 获取账户列表
 */
export const queryAccountList = (data: PageParams) => {
  return http.request<CommonResponse<AccountResult>>("post", "/api/platform/account/list", { data });
}

/**
 * 账户数据类型
 */
export type AccountData = {
  id?: number;
  account: string;
  name: string;
  password: string;
  roleId: string;
}

/**
 * 创建账户
 */
export const createAccount = (data: AccountData) => {
  return http.request<CommonResponse>("post", "/api/platform/account/create", { data });
}

/**
 * 更新账户
 */
export const updateAccount = (data: AccountData) => {
  return http.request<CommonResponse>("post", "/api/platform/account/update", { data });
}

/**
 * 查询所有角色列表
 */
export const queryAllRoleList = () => {
  return http.request<CommonResponse>("get", "/api/platform/role/options");
}

/**
 * 更新账户状态
 */
export const updateAccountStatus = (id: number, status: string) => {
  return http.request<CommonResponse>("post", `/api/platform/account/${id}/status`, { params: { status } });
}